Skip to content

Centralize session-scoped CDP settings to prevent drift across contexts#1181

Open
ctate wants to merge 1 commit intomainfrom
fix/issue-1180-1775544810076
Open

Centralize session-scoped CDP settings to prevent drift across contexts#1181
ctate wants to merge 1 commit intomainfrom
fix/issue-1180-1775544810076

Conversation

@ctate
Copy link
Copy Markdown
Collaborator

@ctate ctate commented Apr 7, 2026

This PR fixes an issue where session-scoped CDP settings configured at browser launch were not being re-applied to new CDP sessions/contexts, causing silent failures when users expected consistent behavior.

Problem

Settings like --user-agent, --color-scheme, --ignore-https-errors, and download behavior were applied during initial browser launch but not propagated to new contexts created by record start, tab new, or window new operations. This meant recordings and new tabs would silently lose these configured behaviors.

Changes

  • Centralized settings application: Created BrowserManager::apply_session_settings() method that applies all session-scoped CDP commands in one place
  • Extended state storage: Added user_agent and color_scheme fields to BrowserManager to persist launch-time configuration
  • Consistent application: Updated all session creation code paths to call apply_session_settings() after attaching to new sessions
  • Eliminated duplication: Replaced inline CDP calls in launch() and handle_recording_start() with centralized method

Implementation Details

The new apply_session_settings() method handles the context-specific requirements of different CDP commands (e.g., Browser.setDownloadBehavior requires browserContextId parameter) and ensures all current and future session-scoped settings are automatically applied to every new session.

Fixes #1180

This PR fixes an issue where session-scoped CDP settings configured at browser launch were not being re-applied to new CDP sessions/contexts, causing silent failures when users expected consistent behavior.

## Problem
Settings like `--user-agent`, `--color-scheme`, `--ignore-https-errors`, and download behavior were applied during initial browser launch but not propagated to new contexts created by `record start`, `tab new`, or `window new` operations. This meant recordings and new tabs would silently lose these configured behaviors.

## Changes
- **Centralized settings application**: Created `BrowserManager::apply_session_settings()` method that applies all session-scoped CDP commands in one place
- **Extended state storage**: Added `user_agent` and `color_scheme` fields to `BrowserManager` to persist launch-time configuration
- **Consistent application**: Updated all session creation code paths to call `apply_session_settings()` after attaching to new sessions
- **Eliminated duplication**: Replaced inline CDP calls in `launch()` and `handle_recording_start()` with centralized method

## Implementation Details
The new `apply_session_settings()` method handles the context-specific requirements of different CDP commands (e.g., `Browser.setDownloadBehavior` requires `browserContextId` parameter) and ensures all current and future session-scoped settings are automatically applied to every new session.

Fixes #1180
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agent-browser Ready Ready Preview, Comment Apr 7, 2026 6:54am
agent-browser-env-demo Ready Ready Preview, Comment Apr 7, 2026 6:54am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Centralize session-scoped CDP settings to prevent drift across contexts

1 participant